package com.xxxx.server.controller;


import com.xxxx.server.pojo.EmployeeEc;
import com.xxxx.server.rest.RespBean;
import com.xxxx.server.query.EmployeeEcQuery;
import com.xxxx.server.service.IEmployeeEcService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/employeeEc/basic")
@Api
public class EmployeeEcController {

    @Resource
    private IEmployeeEcService employeeEcService;

    /**
     * 查询接口
     * @param query
     * @param beginDateScope
     * @return
     */
    @ApiOperation("查询")
    @GetMapping("/")
    public Object select(EmployeeEcQuery query,String beginDateScope){
        if (beginDateScope!=null&&beginDateScope!=""){
            String[] split = beginDateScope.split(",");
            query.setFromDate(split[0]);
            query.setToDate(split[1]);
        }
        Map<String,Object> map=employeeEcService.select(query);
        return map;
    }

    /**
     * 添加接口
     * @param employeeEc
     * @return
     */
    @ApiOperation("添加")
    @PutMapping("/")
    public Object add(@RequestBody EmployeeEc employeeEc){
        System.out.println(employeeEc.toString());
        employeeEcService.add(employeeEc);
        return RespBean.success("添加成功！");
    }

    /**
     * 修改接口
     * @param employeeEc
     * @return
     */
    @ApiOperation("修改")
    @PostMapping("/")
    public Object update(@RequestBody EmployeeEc employeeEc){
        employeeEcService.update(employeeEc);
        return RespBean.success("修改成功！");
    }

    /**
     * 删除接口
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/")
    public Object  delete(@RequestBody EmployeeEc employeeEc){
        employeeEcService.delete(employeeEc.getId());
        return RespBean.success("删除成功！");
    }

    @ApiOperation("导出文件")
    @RequestMapping("/export")
    public void export(EmployeeEcQuery query,HttpServletRequest request, HttpServletResponse response){
        employeeEcService.export(query,request,response);
    }

    @ApiOperation("导入文件")
    @RequestMapping("/import")
    public void upload (MultipartFile file){
        employeeEcService.upload(file);
    }
}